#pragma once
#include "stdafx.h"


//This class is used to sync Ogre SceneNodes with Bullet RigidBodies
namespace ne{
	class MotionState : public btMotionState {
	public:
		MotionState(Ogre::SceneNode* sceneNode) : m_sceneNode(sceneNode), m_centerOfMassOffset(btTransform::getIdentity()) {}
		~MotionState(void){}

		void setWorldTransform(const btTransform& in){
			if (m_sceneNode == nullptr){
				return;
			}
			m_transform = in;
			btTransform transform = in * m_centerOfMassOffset;
			m_sceneNode->setPosition(Convert::ToOgre(transform.getOrigin()));
			m_sceneNode->setOrientation(Convert::ToOgre(transform.getRotation()));
		}

		void getWorldTransform(btTransform& ret) const{
			ret = m_transform;
		}

	private:
		Ogre::SceneNode* m_sceneNode;
		btTransform m_transform;
		btTransform m_centerOfMassOffset;
	};
}